<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>校园二手交易平台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .navbar {
            background-color: #4a6fa5;
        }
        .navbar-brand, .nav-link {
            color: white !important;
        }
        .card {
            transition: transform 0.2s;
            margin-bottom: 20px;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .card-img-top {
            height: 200px;
            object-fit: cover;
        }
        .footer {
            background-color: #4a6fa5;
            color: white;
            padding: 20px 0;
            margin-top: 40px;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="index.html">校园二手交易平台</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link active" href="index.html">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="javascript:void(0)" onclick="filterCategory('学习用品')">学习用品>/li>
                    <li class="nav-item">
                        <a class="nav-link" href="javascript:void(0)" onclick="filterCategory('生活用品')">生活用品>/li>
                    <li class="nav-item">
                        <a class="nav-link" href="post.html">发布物品>/li>
                </ul>
                <!-- 搜索框 -->
                <form class="d-flex" onsubmit="searchItems(event)">
                    <input id="searchInput" class="form-control me-2" type="search" placeholder="搜索商品">
                    <button class="btn btn-light" type="submit">搜索>/button
                </form
            </div
        </div
    </nav

    <!-- 主内容区 -->
    <div class="container mt-5">
        <h1 class="mb-4 text-center" id="pageTitle">最新发布的商品>/h1
        
        <div class="row" id="itemsContainer">
            <!-- 示例商品1 -->
            <div class="col-md-4 item-card" data-category="学习用品" data-name="考研英语词汇书" data-description="全新，未使用过">
                <div class="card">
                    <img src="https://via.placeholder.com/400x200?text=考研英语词汇书" class="card-img-top" alt="考研英语词汇书">
                    <div class="card-body">
                        <h5 class="card-title">考研英语词汇书>/h5
                        <p class="card-text text-danger font-weight-bold" style="font-size: 1.2rem;">¥35.00>/p
                        <p class="card-text" style="max-height: 60px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">全新，未使用过，适合2025年考研学生使用>/p
                        <div class="mt-3">
                            <span class="badge bg-secondary">学习用品>/span
                            <span class="badge bg-info ms-2">联系方式: QQ123456789>/span
                        </div
                    </div
                </div
            </div
            
            <!-- 示例商品2 -->
            <div class="col-md-4 item-card" data-category="生活用品" data-name="便携式加湿器" data-description="九成新，使用过几次">
                <div class="card">
                    <img src="https://via.placeholder.com/400x200?text=便携式加湿器" class="card-img-top" alt="便携式加湿器">
                    <div class="card-body">
                        <h5 class="card-title">便携式加湿器>/h5
                        <p class="card-text text-danger font-weight-bold" style="font-size: 1.2rem;">¥25.00>/p
                        <p class="card-text" style="max-height: 60px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">九成新，使用过几次，适合宿舍使用，USB充电口>/p
                        <div class="mt-3">
                            <span class="badge bg-secondary">生活用品>/span
                            <span class="badge bg-info ms-2">联系方式: 微信wx123456789>/span
                        </div
                    </div
                </div
            </div
            
            <!-- 示例商品3 -->
            <div class="col-md-4 item-card" data-category="学习用品" data-name="机械键盘" data-description="游戏键盘，青轴">
                <div class="card">
                    <img src="https://via.placeholder.com/400x200?text=机械键盘" class="card-img-top" alt="机械键盘">
                    <div class="card-body">
                        <h5 class="card-title">机械键盘>/h5
                        <p class="card-text text-danger font-weight-bold" style="font-size: 1.2rem;">¥120.00>/p
                        <p class="card-text" style="max-height: 60px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">游戏键盘，青轴，打字声音清脆，手感好，适合编程和游戏使用>/p
                        <div class="mt-3">
                            <span class="badge bg-secondary">学习用品>/span
                            <span class="badge bg-info ms-2">联系方式: QQ987654321>/span
                        </div
                    </div
                </div
            </div
        </div
    </div

    <!-- 页脚 --</footer class="footer">
        <div class="container text-center">
            <p>&copy; 2024 校园二手交易平台 - 让闲置物品流动起来>/p
        </div
    </footer

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script
    <script>
        // 分类筛选功能
        function filterCategory(category) {
            const cards = document.querySelectorAll('.item-card');
            const pageTitle = document.getElementById('pageTitle');
            let hasItems = false;
            
            pageTitle.textContent = category;
            
            cards.forEach(card => {
                if (card.dataset.category === category) {
                    card.style.display = 'block';
                    hasItems = true;
                } else {
                    card.style.display = 'none';
                }
            });
            
            // 显示空状态
            const itemsContainer = document.getElementById('itemsContainer');
            const emptyState = document.getElementById('emptyState');
            
            if (!hasItems && !emptyState) {
                const emptyDiv = document.createElement('div');
                emptyDiv.id = 'emptyState';
                emptyDiv.className = 'col-12 text-center';
                emptyDiv.innerHTML = '<h3 class="text-muted">暂无商品信息</h3>';
                itemsContainer.appendChild(emptyDiv);
            }
        }
        
        // 搜索功能
        function searchItems(event) {
            event.preventDefault();
            const keyword = document.getElementById('searchInput').value.toLowerCase();
            const cards = document.querySelectorAll('.item-card');
            const pageTitle = document.getElementById('pageTitle');
            let hasItems = false;
            
            pageTitle.textContent = `搜索结果: ${keyword}`;
            
            // 移除之前的空状态
            const emptyState = document.getElementById('emptyState');
            if (emptyState) {
                emptyState.remove();
            }
            
            cards.forEach(card => {
                const name = card.dataset.name.toLowerCase();
                const description = card.dataset.description.toLowerCase();
                
                if (name.includes(keyword) || description.includes(keyword)) {
                    card.style.display = 'block';
                    hasItems = true;
                } else {
                    card.style.display = 'none';
                }
            });
            
            // 显示空状态
            const itemsContainer = document.getElementById('itemsContainer');
            if (!hasItems) {
                const emptyDiv = document.createElement('div');
                emptyDiv.id = 'emptyState';
                emptyDiv.className = 'col-12 text-center';
                emptyDiv.innerHTML = '<h3 class="text-muted">没有找到相关商品</h3>';
                itemsContainer.appendChild(emptyDiv);
            }
        }
    </script
</body
</html